package cn.xd.base.persistence.mps.impl;

import cn.hutool.core.util.ObjUtil;
import cn.xd.base.persistence.dos.AdminUserDO;
import cn.xd.base.persistence.mapper.AdminUserMapper;
import cn.xd.base.persistence.mps.AdminUserMpService;
import cn.xd.common.enums.common.CommonStatusEnum;
import cn.xd.core.response.ObjectResult;
import cn.xd.core.service.impl.BasicMpServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

@Service
public class AdminUserMpServiceImpl extends BasicMpServiceImpl<AdminUserMapper, AdminUserDO> implements AdminUserMpService {
    @Override
    public ObjectResult<AdminUserDO> getAdminUserByAccount(String account, Long neId) {
        return getOneForLimitOneResult(new LambdaQueryWrapper<AdminUserDO>()
                .ne(ObjUtil.isNotNull(neId), AdminUserDO::getId, neId)
                .eq(AdminUserDO::getAccount, account)
                .ne(AdminUserDO::getStatus, CommonStatusEnum.DELETED.getCode()));
    }

    @Override
    public ObjectResult<AdminUserDO> getAdminUserByGlobalUserId(Long globalUserId, Long neId) {
        return getOneForLimitOneResult(new LambdaQueryWrapper<AdminUserDO>()
                .ne(ObjUtil.isNotNull(neId), AdminUserDO::getId, neId)
                .eq(AdminUserDO::getGlobalUserId, globalUserId)
                .ne(AdminUserDO::getStatus, CommonStatusEnum.DELETED.getCode()));
    }
}
